import 'package:flutter/material.dart';
import 'package:flutter_architecture/src/utils/async_value_ui.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'account_screen_controller.dart';

class AccountScreen extends ConsumerWidget {
  const AccountScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    ref.listen<AsyncValue>(accountScreenControllerProvider,
        (_, state) => state.showSnackBarOnError(context));
    final state = ref.watch(accountScreenControllerProvider);
    return Scaffold(
      appBar: AppBar(
        title: state.isLoading
            ? const CircularProgressIndicator()
            : const Text("Account"),
        actions: [
          TextButton(
              onPressed: state.isLoading
                  ? null
                  : () async {
                      ref
                          .read(accountScreenControllerProvider.notifier)
                          .signOut();
                    },
              child: Text(
                'Logout',
                style: Theme.of(context)
                    .textTheme
                    .titleLarge
                    ?.copyWith(color: Colors.blue),
              ))
        ],
      ),
    );
  }
}
